package com.hqyj.springbootday01.controller;

import com.hqyj.springbootday01.entity.ApplicationTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Test Controller
 */
@Controller
@RequestMapping("/test")
public class TestController {

	@Value("${com.sfac.name}")
	private String name;
	@Value("${com.sfac.age}")
	private int age;
	@Value("${com.sfac.desc}")
	private String desc;
	@Value("${com.sfac.random}")
	private String random;
	@Autowired
	private ApplicationTest applicationTest;
	private final static Logger LOGGER = LoggerFactory.getLogger(TestController.class);

	/**
	 * 127.0.0.1/test/helloWorld ---- get
	 */
	@GetMapping(value = "/helloWorld")
	@ResponseBody
	public String helloWorld() {
		return "Hello World!!!!!!!";
	}

	/**
	 * 127.0.0.1/test/config ---- get
	 */
	@GetMapping(value = "/config")
	@ResponseBody
	public String configTest() {
		return String.format("%s--%s--%s--%s---%s--%s--%s--%s",
				name, age, desc, random,
				applicationTest.getName(),
				applicationTest.getAge(),
				applicationTest.getDesc(),
				applicationTest.getRandom());
	}

	/**
	 * 127.0.0.1/test/log ---- get
	 */
	@GetMapping(value = "/log")
	@ResponseBody
	public String logbackTest() {
		LOGGER.trace("This is trace log.");
		LOGGER.debug("This is debug log.");
		LOGGER.info("This is info log.");
		LOGGER.warn("This is warn log.");
		LOGGER.error("This is error log.");
		return "This is logback test.";
	}
}
